import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { catchError, map } from 'rxjs/operators';
import { TokenService } from './token.service';
import { LOGIN_URL } from '../../shared/constants/api';


@Injectable()
export class LoginService {
  constructor(
    private http: HttpClient,
    private tokenService: TokenService
  ) {}

  login(username: string, password: string) {
    if (!this.tokenService.getFlag()) {
      const options = { params: new HttpParams().set('username', username).set('password', password) };
      this.http.post(LOGIN_URL, options).pipe(
        map((data) => console.log(data))
      );
    }
  }

}
